package com.chinaztt.fda.test.glide;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chinaztt.fda.ui.R;

/**
 * @Description Glide图片缓存管理类
 * @Creator wushan
 * @Date 2016/10/11 14:41
 */
public class GlideManager {

    private Context mContext;
    private RequestManager mRequestManager;

    public GlideManager(Context context) {
        mContext = context;
        init();
    }

    public void init(){
        mRequestManager = Glide.with(mContext);
    }

    /**
     * 从指定url加载图片设置到ImageView
     * @param url
     * @param view
     */
    public void LoadImage(String url, ImageView view){
        if(mRequestManager != null){
            mRequestManager.load(url)
                    .diskCacheStrategy(DiskCacheStrategy.RESULT)
                    .transform(new GlideRoundTransform(mContext, 10))
                    .placeholder(R.mipmap.ic_launcher)//默认加载的图片
                    .error(R.color.red)           //加载错误时显示<可指定图片>
                    .crossFade()
                    .into(view);
        }
    }

    /**
     * 加载指定资源id的图片设置到ImageView
     * @param resourceId
     * @param view
     */
    public void LoadImage(Integer resourceId, ImageView view){
        if(mRequestManager != null){
            mRequestManager.load(resourceId)
                    .diskCacheStrategy(DiskCacheStrategy.RESULT)
                    .transform(new GlideRoundTransform(mContext, 10))
                    .placeholder(R.mipmap.ic_launcher)//默认加载的图片
                    .error(R.color.red)           //加载错误时显示<可指定图片>
                    .crossFade()
                    .into(view);
        }
    }


}
